#include <cstdio>

int main() {
    const int MAX = 1111;
    int K, e, count = 0;
    double c, num[MAX+10] = {};

    scanf("%d", &K);
    for (int i = 0; i < K; i++) {
        scanf("%d%lf", &e, &c);
        num[e] += c;
    }
    scanf("%d", &K);
    for (int i = 0; i < K; i++) {
        scanf("%d%lf", &e, &c);
        num[e] += c;
    }
    
    for (int i = 0; i < MAX; i++) {
        if (num[i] != 0) {
            count++;
        }
    }
    printf("%d", count);

    for (int i = MAX-1; i >= 0; i--) {
        if (num[i] != 0) {
            printf(" %d %.1f", i, num[i]);
        }
    }


    return 0;
}